package com.itguigu.glimail.oauth;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 核心原理
 * @EnableRedisHttpSession 导入RedisHttpSessionConfiguration配置
 *1、给容器中添加了一个组件
 * SessionRepository=>》》[RedisOperationsSessionRepository] ==> redis操作session. session的增删改查封装类
 * 2、SessionRepositoryFilter==》 Filter: session 存储过滤器;每个请求过来都必须经过filter
 * 1、创建的时候，就自动从容器中获取到了SessionRepository;
 * 2、原始的request, response都被包装。 SessionRepositoryRequestlrapper, SessionRepositoryResponsel
 *3、以后获取session. request. getSession();
 * 4、wrappedReqfest. getSession();===> SessionRepository 中获取到的。
 * 装饰者模式;
 *session 自动延期  redis中的session也有过期时间
 *
 *
 *
 * @Override
 *        protected void doFilterInternal(HttpServletRequest request,
 * 			HttpServletResponse response, FilterChain filterChain)
 * 			throws ServletException, IOException {
 * 		request.setAttribute(SESSION_REPOSITORY_ATTR, this.sessionRepository);
 *
 * 		SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryRequestWrapper(
 * 				request, response, this.servletContext);
 * 		SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryResponseWrapper(
 * 				wrappedRequest, response);
 *
 * 		try {
 * 			filterChain.doFilter(wrappedRequest, wrappedResponse);
 *        }
 * 		finally {
 * 			wrappedRequest.commitSession();
 *        }
 *    }
 *
 */

@EnableFeignClients(basePackages = "com.itguigu.glimail.oauth.feign")
@EnableDiscoveryClient
@SpringBootApplication
public class GlimailOauthServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(GlimailOauthServerApplication.class, args);
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
